﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cart
{
    public partial class Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtEmail.Attributes.Add("onblur", "javascript:if(this.value == '')this.value='Email đăng nhập';");
            txtEmail.Attributes.Add("onfocus", "javascript:if(this.value == 'Email đăng nhập') this.value='';");
            txtPass.Attributes.Add("value", "!@#$%^");
            txtPass.Attributes.Add("onblur", "javascript:if(this.value == '')this.value='!@#$%^';");
            txtPass.Attributes.Add("onfocus", "javascript:if(this.value == '!@#$%^') this.value='';");
        }


        protected void btSubmit_Click(object sender, EventArgs e)
        {
            using (var ndService = new NguoiDungSrv.NguoiDungServiceClient())
            {
                var result = ndService.Login(txtEmail.Text, txtPass.Text);
                if (result != null)
                {
                    if (result.TrangThai == 1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('Tài khoản đã bị khóa !'); window.location='" + Request.ApplicationPath + "TrangChu.aspx';", true);
                    }
                    else
                    {
                        Session["nsd"] = result;
                        Response.Redirect("~/TrangChu.aspx");
                    }
                    
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('Tài khoản hoặc mật khẩu sai !'); window.location='" + Request.ApplicationPath + "TrangChu.aspx';", true);
                }
            }
        }
    }
}